<?php
/**
 *	[alias(alias.{modulename})] (C)2012-2099 Powered by abans@qq.com.
 *	Version: 1.8
 *	Date: 2012-12-26 13:35
 */
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
loadcache('plugin');
if(!defined('Adz_class')) include('Adz.class.php');
if(!defined('Adz_alias_fun')) include('alias.fun.php');
autojump();
foreach ($_G['setting']['domain']['list'] as $k => $v) {
	$alist[$v['idtype']][$v['id']] = $k;
}
$_G['setting']['domain']['alist'] = $alist;
//增强rss,帖子伪静态设置
if($_G['cache']['plugin']['alias']['forum_path']==1){
	$_G['setting']['output']['preg']['replace']['forum_forumdisplay'] = "Arewriteoutput('forum_forumdisplay', 0, '\\1', '\\3', '\\5', '\\6')";
	$_G['setting']['output']['preg']['replace']['forum_viewthread'] = "Arewriteoutput('forum_viewthread_path', 0, '\\1', '\\3', '\\8', '\\6', '\\9')";
}else{
	$_G['setting']['output']['preg']['replace']['forum_viewthread'] = "Arewriteoutput('forum_viewthread', 0, '\\1', '\\3', '\\8', '\\6', '\\9')";
}
$_G['setting']['output']['preg']['search']['forum_rss'] = "/<a href\=\"([^\>]*)?forum.php\?mod\=rss&(amp;)?fid\=(\d+)(&amp;auth\=(.+))?\"([^\>]*)\>/e";
$_G['setting']['output']['preg']['replace']['forum_rss'] = "Arewriteoutput('forum_rss', 0, '\\1', '\\3', '\\5', '\\6')";
$_G['setting']['output']['preg']['search']['forum_gid'] = "/<a href\=\"([^\>]*)?forum.php\?gid\=([\d]+)?\"([^\>]*)\>/e";
$_G['setting']['output']['preg']['replace']['forum_gid'] = "Arewriteoutput('forum_forumdisplay', 0, '\\1', '\\2','','')";
if($_G['cache']['plugin']['alias']['tag_enable']==1){
	$_G['setting']['output']['preg']['search']['tag'] = "/<a href\=\"misc.php\?mod\=tag\"([^\>]*)\>/e";
	$_G['setting']['output']['preg']['replace']['tag'] = "Arewriteoutput('tag', 0, '\\1')";
	$_G['setting']['output']['preg']['search']['tags'] = '/<a (title\="[\w\s\d\. &\%!?-_~#\x7f-\xff]+" )?href\="(.*?)misc.php\?mod\=tag&(amp;)?id\=(\d+)?"([^\>]*)?\>/e';
	$_G['setting']['output']['preg']['replace']['tags'] = "Arewriteoutput('tags', 0, '\\2', '\\4', '\\1', '\\6')";
}

class plugin_alias {
	public function common() {}
	public function plugin_alias(){
		global $_G;
		if($_G['tid']){
			if(@in_array('forum_viewthread', $_G['setting']['rewritestatus'])) {
				$canonical = Arewriteoutput('forum_viewthread', 1, '', $_G['tid'], 1, '', '');
			} else {
				$canonical = 'forum.php?mod=viewthread&tid='.$_G['tid'];
			}
			$_G['setting']['seohead'] = '<link href="'.$_G['siteurl'].$canonical.'" rel="canonical" />';
		}
	}
}
class plugin_alias_forum extends plugin_alias {
	function plugin_alias_forum(){
		global $_G;
		$this->conf = $_G['cache']['plugin']['alias'];
	}
	
	function viewthread_top(){
		//$html = '333';
		//return $html;
	}
	
	/**浏览帖子标题挂载点 */
	function viewthread_title_extra() {
		global $_G;
		$title = $_G[forum_thread][subject];
		$tid = $_G['tid'];
		if (Adz::auth('alias',2)){
			$html = Adz::acan_ui('alias').'
<style>
._alias{padding: 5px 10px 5px 20px;}
</style>
<script src="source/plugin/alias/acan/js/alias.js"></script>';
			$data = Adz::fetch_con('plugin_alias_bind',array('rid'=>$tid,'type'=>1));
			if($data){
				$alias = $data['alias'];
			}
			$html .= '<a class="editp _alias" onClick="alias_edit(\''.$tid.'\',\''.$title.'\',\''.$alias.'\',1)">'.lang('plugin/alias','alias').'</a>';
		}
		return $html;
	}
	
	/**发帖回帖成功挂载点 */
	function post_sync_to_alias_aftersubmit_message($param) {
		if($this->_check_is_forum_post($param)>0){
			if($this->conf['ping_baidu']==1){
				alias_ping($param['param'][2]['tid']);
			}
			if($this->conf['ping_google']==1){
				alias_ping($param['param'][2]['tid'],'google');
			}
		}
	}
	/**检测发帖回帖类型 */
	function _check_is_forum_post($param) {
		global $_G;
		if(!$_G['uid'] || 'POST' != $this->_get_request_method() || substr($param['param'][0], -8) != '_succeed'){
			return 0;
		}else if(isset($param['param'][2]['tid']) && ($param['param'][2]['tid'] > 0)){
			if(submitcheck('topicsubmit') && $_G['gp_action'] == 'newthread'){
				//&& $_G['cache']['plugin']['alias']['ping_new']
				return 1;
			}else if(submitcheck('replysubmit') && $_G['gp_action'] == 'reply'){
				//&& $_G['cache']['plugin']['alias']['ping_reply']
				return 2;
			}else if(submitcheck('editsubmit') && $_G['gp_action'] == 'edit'){
				//&& $_G['cache']['plugin']['alias']['ping_edit']
				return 3;
			}else{
				return 0;
			}
		}else{
			return 0;
		}
	}
	function _get_request_method() {
		static $_requestMethod = null;
		if( null == $_requestMethod ){
			$_requestMethod = isset($_SERVER['REQUEST_METHOD']) ? strtoupper($_SERVER['REQUEST_METHOD']) : '';
		}
		return $_requestMethod;
	}
}

?>